import request from "@/api/request";

/**
 * 获取列表
 * @param params 参数
 */
export function getPage(params: SearchListParams) {
  return request({
    url: "/system/role/page",
    method: "get",
    params: params,
  });
}

/**
 * 获取列表
 */
export function getList() {
  return request({
    url: "/system/role/list",
    method: "get",
  });
}

/**
 * 获取详情
 * @param params 参数
 */
export function getInfo(params: number) {
  return request({
    url: "/system/role/" + params,
    method: "get",
  });
}

/**
 * 新增
 * @param params 参数
 */
export function saveInfo(params: DataInfo) {
  return request({
    url: "/system/role/save",
    method: "post",
    data: params,
  });
}

/**
 * 修改
 * @param params 参数
 */
export function editInfo(params: DataInfo) {
  return request({
    url: "/system/role/update",
    method: "post",
    data: params,
  });
}

/**
 * 删除
 * @param params 参数
 */
export function deleteInfo(params: number | number[]) {
  return request({
    url: "/system/role/remove/" + params.toString(),
    method: "get",
  });
}

/**
 * 获取角色菜单关联表
 * @param params 角色id和菜单id集合
 */
export function roleMenuList(params: number | undefined){
  return request({
      url: "/system/role/listRoleMenu/" + params,
      method: "get",
  });
}

/**
 * 修改角色菜单关联表
 * @param params 角色id和菜单id集合
 */
export function editRoleMenu(params: {roleId: number | null | undefined, menuIds: number[]}){
    return request({
        url: "/system/role/editRoleMenu",
        method: "post",
        data: params,
    });
}

export interface SearchListParams {
  pageNum: number;
  pageSize: number;
  name: string;
  roleKey: string;
}

export interface DataInfo {
  id: number | null;
  name: string;
  roleKey: string;
  sort: number | null;
}

export interface TableData {
  id: number;
  name: string;
  roleKey: string;
  sort: number;
  createTime: string;
  updateTime: string;
}
